package core;

import java.util.Set;

import core.context.InputContext;
import core.context.OutputContext;
import core.strategy.TowerStrategy;
import domain.Square;
import domain.Tower;

public class TowerManager {
	private static TowerManager manager = new TowerManager();

	private TowerStrategy strategy;

	private TowerManager() {
		strategy = TowerStrategy.getInstance();

	}

	public static TowerManager getManager() {
		return manager;
	}

	public void makeTower(InputContext context, OutputContext outputContext) {
		Set<Tower> towers = strategy.generateTowers(context);
		Square[][] map = context.getMap();
		context.getTowers().clear();
		outputContext.getTowers().clear();
		for (Tower tower : towers) {
			try {
				map[tower.getPosition().getY()][tower.getPosition().getX()]
						.setTower(tower);
				context.addTower(tower);
				outputContext.addTower(tower);
			} catch (Exception e) {

			}

		}

	}

}
